Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Runtime.InteropServices
Imports System.Configuration
Imports System.Text
Public Class AdminTerminals
    Public DBConnectString As String
    'Private oAudit As viaAudit.AuditEvent
    Private x As String
    Public SESSION_USER_ID As String
    Public SESSION_VIAKLIX_ID As String
    Public SESSION_COMPANY_ID As Integer
    Public ServerIP As String
    Public ServerTime As String
    Public SourceIP As String
    Public ErrMsg As String


    'Public Function GetMerchantTerminals(ByVal VID As String) As Object

    '    Dim Conn As SqlConnection
    '    Dim Rs As DataSet
    '    Dim Cmd As SqlCommand
    '    Dim vTerminalList As Object
    '    Conn = New SqlConnection
    '    Rs = New DataSet
    '    ' Dim sqladp As SqlDataAdapter
    '    'Conn.Open(DBConnectString)
    '    Cmd = New SqlCommand
    '    'Cmd.ActiveConnection = Conn
    '    With Cmd
    '        .Connection = Conn

    '        .CommandType = CommandType.StoredProcedure
    '        .CommandText = "VIAKLIX_PROCESSING.GETMERCHANTTERMINALS"
    '        .Parameters.Add(New SqlParameter("@i_vid", SqlDbType.VarChar, 15)).Value = VID
    '        .Parameters.Add(New SqlParameter("@o_ERRORMSG", SqlDbType.VarChar, 255)).Direction = ParameterDirection.Output
    '        'Rs.CursorType = adOpenForwardOnly
    '        'Rs.CursorLocation = adUseServer
    '        'Rs = Cmd.Execute
    '    End With
    '    ' sqladp.SelectCommand.CommandType = CommandType.StoredProcedure
    '    ' sqladp.Fill(Rs, "GETMERCHANTTERMINALS")
    '    '------------------------------------------------------------------------
    '    'Returns a message to the calling ASP page.
    '    '------------------------------------------------------------------------
    '    If Not IsNothing(Cmd.Parameters("o_ERRORMSG").Value) Then
    '        'Rs = Nothing

    '        'Debug.Print("Error Msg = " & Cmd.Parameters("o_ERRORMSG"))
    '        ErrMsg = Cmd.Parameters("o_ERRORMSG").Value

    '        'Cmd = Nothing
    '        'Conn.Close()
    '        'Conn = Nothing

    '    End If
    '    '------------------------------------------------------------------------

    '    'If Not Is""(Cmd.Parameters("o_ERRORMSG")) Then
    '    '    Debug.Print ("Error Msg = " & Cmd.Parameters("o_ERRORMSG"))
    '    '    Exit Function
    '    'End If
    '    If Rs.Tables(0).Rows.Count > 0 Then
    '        vTerminalList = Rs.Tables(0).Rows.Count
    '        'Cmd = Nothing
    '        'Conn = Nothing
    '        GetMerchantTerminals = vTerminalList
    '        Exit Function
    '    End If

    '    'ErrorHandler:
    '    '        Call LogErrorEvent("AdminTerminals.GetMerchantTerminals")

    '    '        If Not Rs Is Nothing Then
    '    '            If Rs.State <> adStateClosed Then
    '    '                Rs.Close()
    '    '            End If

    '    '            Rs = Nothing
    '    '        End If

    '    '        If Not Conn Is Nothing Then
    '    '            If Conn.State <> adStateClosed Then
    '    '                Conn.Close()
    '    '            End If

    '    '            Conn = Nothing
    '    '        End If

    '    '        Cmd = Nothing
    '    Return Nothing
    'End Function

    'Public Function EditTerminals(ByVal UID As String, _
    '        ByVal VID As String, _
    '        ByVal CID As Integer, _
    '        ByVal TID As String, _
    '        ByVal fName As String, _
    '        ByVal market As String, _
    '        ByVal action As String) As Boolean

    '    'On Error GoTo ErrorHandler
    '    Dim Conn As SqlConnection
    '    Dim Cmd As SqlCommand
    '    Dim Sql As String
    '    ' Dim oAudit As gaAugit.AuditEvent
    '    If action = "Add" Then
    '        Dim sPin As String
    '        Dim i As Integer
    '        Dim valpha As Object
    '        Dim nSides As Integer
    '        Dim GeneralResult As Integer

    '        valpha = Split("A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z", ",")
    '        nSides = 36
    '        For i = 0 To 6 - 1
    '            Randomize()
    '            GeneralResult = Int(nSides * Rnd())
    '            If GeneralResult < 10 Then
    '                sPin = sPin & GeneralResult
    '            Else
    '                sPin = sPin & valpha(GeneralResult - 10)
    '            End If
    '        Next i

    '        Conn = New SqlConnection
    '        'Conn.Open(DBConnectString)
    '        Cmd = New SqlCommand
    '        With Cmd
    '            .Connection = Conn
    '            .CommandType = CommandType.StoredProcedure
    '            .CommandText = "VIAKLIX_PROCESSING.INSTERMINAL"
    '            .Parameters.Add(New SqlParameter("@i_tnumber", SqlDbType.VarChar, 22)).value = TID
    '            .Parameters.Add(New SqlParameter("@i_cid", SqlDbType.Int, 4)).Value = CID
    '            .Parameters.Add(New SqlParameter("@i_vid", SqlDbType.VarChar, 15)).value = VID
    '            .Parameters.Add(New SqlParameter("@i_fname", SqlDbType.VarChar, 30)).value = fName
    '            .Parameters.Add(New SqlParameter("@i_market", SqlDbType.VarChar, 30)).value = market
    '            .Parameters.Add(New SqlParameter("@i_pin", SqlDbType.VarChar, 6)).value = sPin

    '            '"" Paramaters, these are only set when calling this stored proc from within Create Merchant
    '            .Parameters.Add(New SqlParameter("@i_terminalemail", SqlDbType.VarChar, 255)).value = ""
    '            .Parameters.Add(New SqlParameter("@i_merchantname", SqlDbType.VarChar, 100)).value = ""
    '            .Parameters.Add(New SqlParameter("@i_add1", SqlDbType.VarChar, 100)).value = ""
    '            .Parameters.Add(New SqlParameter("@i_add2", SqlDbType.VarChar, 100)).value = ""
    '            .Parameters.Add(New SqlParameter("@i_city", SqlDbType.VarChar, 50)).value = ""
    '            .Parameters.Add(New SqlParameter("@i_state", SqlDbType.VarChar, 2)).value = ""
    '            .Parameters.Add(New SqlParameter("@i_zip", SqlDbType.VarChar, 10)).value = ""
    '            .Parameters.Add(New SqlParameter("@i_contactName", SqlDbType.VarChar, 100)).value = ""
    '            .Parameters.Add(New SqlParameter("@i_contactphone1", SqlDbType.VarChar, 20)).value = ""
    '            .Parameters.Add(New SqlParameter("@i_contactphone2", SqlDbType.VarChar, 20)).value = ""
    '            .Parameters.Add(New SqlParameter("@i_contactemail", SqlDbType.VarChar, 100)).value = ""
    '            .Parameters.Add(New SqlParameter("@i_merchanturl", SqlDbType.VarChar, 255)).value = ""
    '            .Parameters.Add(New SqlParameter("@0_errormsg", SqlDbType.VarChar, 255)).Direction = ParameterDirection.Output
    '        End With

    '        '------------------------------------------------------------------------
    '        'Returns a message to the calling ASP page.
    '        '------------------------------------------------------------------------
    '        If Not IsNothing(Cmd.Parameters("0_errormsg").value) Then
    '            EditTerminals = False

    '            'Debug.Print("Error Msg = " & Cmd.Parameters("0_errormsg"))
    '            ErrMsg = Cmd.Parameters("0_errormsg").value

    '            'Cmd = Nothing
    '            'Conn.Close()
    '            'Conn = Nothing
    '            Exit Function
    '        Else
    '            '------------------------------------------------------------------------

    '            EditTerminals = True
    '            Cmd = Nothing
    '            Conn.Close()
    '            Conn = Nothing

    '            'oAudit = New gaAugit.AuditEvent  'CreateObject("viaAudit.AuditEvent")
    '            oAudit.DBConnectString = DBConnectString
    '            oAudit.SESSION_USER_ID = SESSION_USER_ID
    '            oAudit.SESSION_GAPORTAL_ID = SESSION_VIAKLIX_ID
    '            oAudit.SESSION_COMPANY_ID = SESSION_COMPANY_ID
    '            oAudit.AFFECTED_USER_ID = UID
    '            oAudit.AFFECTED_GAPORTAL_ID = VID
    '            oAudit.AFFECTED_COMPANY_ID = CInt(CID)
    '            oAudit.AddInfo(68, ServerIP)
    '            oAudit.AddInfo(69, ServerTime)
    '            oAudit.AddInfo(70, SourceIP)
    '            oAudit.AddInfo(75, TID)
    '            oAudit.EventID = 16  '-----  Add New Terminal Number
    '            x = oAudit.SaveEvent()
    '            oAudit = Nothing

    '            Exit Function
    '        End If

    '    ElseIf action = "Update" Then
    '        Conn = New SqlConnection
    '        'Conn.Open(DBConnectString)

    '        Cmd = New SqlCommand
    '        With Cmd
    '            .Connection = Conn
    '            .CommandType = CommandType.StoredProcedure
    '            .CommandText = "VIAKLIX_PROCESSING.UPDTERMINAL"
    '            .Parameters.Add(New SqlParameter("@i_tid", SqlDbType.VarChar, 22)).Value = TID
    '            .Parameters.Add(New SqlParameter("@i_vid", SqlDbType.VarChar, 15)).Value = VID
    '            .Parameters.Add(New SqlParameter("@i_friendlyname", SqlDbType.VarChar, 30)).Value = fName
    '            .Parameters.Add(New SqlParameter("@i_market", SqlDbType.VarChar, 30)).Value = market
    '            .Parameters.Add(New SqlParameter("@0_errormsg", SqlDbType.VarChar, 255)).Direction = ParameterDirection.Output
    '        End With
    '        Cmd.Connection.Open()
    '        Cmd.ExecuteNonQuery()
    '        '------------------------------------------------------------------------
    '        'Returns a message to the calling ASP page.
    '        '------------------------------------------------------------------------
    '        If Not IsNothing(Cmd.Parameters("0_errormsg").Value) Then
    '            EditTerminals = False

    '            'Debug.Print("Error Msg = " & Cmd.Parameters("0_errormsg"))
    '            ErrMsg = Cmd.Parameters("0_errormsg").Value

    '            Cmd = Nothing
    '            Conn.Close()
    '            Conn = Nothing
    '            EditTerminals = False
    '            Exit Function
    '        End If
    '        '------------------------------------------------------------------------

    '        'If Not Is""(Cmd.Parameters("0_errormsg")) Then
    '        '    EditTerminals = False
    '        '    Set Cmd = Nothing
    '        '    Conn.Close
    '        '    Set Conn = Nothing
    '        '    Debug.Print ("Error Msg = " & Cmd.Parameters("0_errormsg"))
    '        '    Exit Function
    '        'Else
    '        EditTerminals = True
    '        Cmd = Nothing
    '        Conn.Close()
    '        Conn = Nothing

    '        oAudit = New gaAugit.AuditEvent 'CreateObject("viaAudit.AuditEvent")
    '        oAudit.DBConnectString = DBConnectString
    '        oAudit.SESSION_USER_ID = SESSION_USER_ID
    '        oAudit.SESSION_GAPORTAL_ID = SESSION_VIAKLIX_ID
    '        oAudit.SESSION_COMPANY_ID = SESSION_COMPANY_ID
    '        oAudit.AFFECTED_USER_ID = UID
    '        oAudit.AFFECTED_GAPORTAL_ID = VID
    '        oAudit.AFFECTED_COMPANY_ID = CInt(CID)
    '        oAudit.AddInfo(68, ServerIP)
    '        oAudit.AddInfo(69, ServerTime)
    '        oAudit.AddInfo(70, SourceIP)
    '        oAudit.AddInfo(75, TID)
    '        oAudit.EventID = 7  '----- terminal number change
    '        x = oAudit.SaveEvent()
    '        oAudit = Nothing

    '        Exit Function
    '        'End If


    '    ElseIf action = "Delete" Then
    '        Conn = New SqlConnection
    '        'Conn.Open(DBConnectString)
    '        Cmd = New SqlCommand
    '        With Cmd
    '            .Connection = Conn
    '            .CommandType = CommandType.StoredProcedure
    '            .CommandText = "VIAKLIX_PROCESSING.DELETETERMINAL"
    '            .Parameters.Add(New SqlParameter("@i_tid", SqlDbType.VarChar, 22)).Value = TID
    '            .Parameters.Add(New SqlParameter("@0_errormsg", SqlDbType.VarChar, 255)).Direction = ParameterDirection.Output
    '        End With
    '        Cmd.Connection.Open()
    '        Cmd.ExecuteNonQuery()
    '        '------------------------------------------------------------------------
    '        'Returns a message to the calling ASP page.
    '        '------------------------------------------------------------------------
    '        If Not IsNothing(Cmd.Parameters("0_ERRORMSG").Value) Then
    '            EditTerminals = False

    '            'Debug.Print("Error Msg = " & Cmd.Parameters("0_ERRORMSG"))
    '            ErrMsg = Cmd.Parameters("0_ERRORMSG").Value

    '            Cmd = Nothing
    '            Conn.Close()
    '            Conn = Nothing
    '            Exit Function
    '        End If
    '        '------------------------------------------------------------------------

    '        'If Not Is""(Cmd.Parameters("0_errormsg")) Then
    '        '    Debug.Print ("Error Msg = " & Cmd.Parameters("0_errormsg"))
    '        '    EditTerminals = False
    '        '    Set Cmd = Nothing
    '        '    Conn.Close
    '        '    Set Conn = Nothing
    '        '    Exit Function
    '        'Else
    '        EditTerminals = True
    '        Cmd = Nothing
    '        Conn.Close()

    '        Conn = Nothing
    '        oAudit = CreateObject("viaAudit.AuditEvent")
    '        oAudit.DBConnectString = DBConnectString
    '        oAudit.SESSION_USER_ID = SESSION_USER_ID
    '        oAudit.SESSION_GAPORTAL_ID = SESSION_VIAKLIX_ID
    '        oAudit.SESSION_COMPANY_ID = SESSION_COMPANY_ID
    '        oAudit.AFFECTED_USER_ID = UID
    '        oAudit.AFFECTED_GAPORTAL_ID = VID
    '        oAudit.AFFECTED_COMPANY_ID = CInt(CID)
    '        oAudit.AddInfo(68, ServerIP)
    '        oAudit.AddInfo(69, ServerTime)
    '        oAudit.AddInfo(70, SourceIP)
    '        oAudit.AddInfo(75, TID)
    '        oAudit.EventID = 17  '-----  Pin and terminal number deletion
    '        x = oAudit.SaveEvent()
    '        oAudit = Nothing

    '        Exit Function
    '        'End If
    '    End If


    '    Exit Function
    '    'ErrorHandler:
    '    '        Call LogErrorEvent("AdminTerminals.EditTerminals")

    '    '        If Not Conn Is Nothing Then
    '    '            If Conn.State <> adStateClosed Then
    '    '                Conn.Close()
    '    '            End If

    '    '            Conn = Nothing
    '    '        End If

    '    '        oAudit = Nothing
    '    '        Cmd = Nothing
    'End Function

    'Private Sub LogErrorEvent(ByVal sOrigin As String)
    '    Dim sErrMsg As String
    '    sErrMsg = ""
    '    sErrMsg = sErrMsg & "viaMerchAccount." & sOrigin & vbCrLf
    '    sErrMsg = sErrMsg & "Source: " & Err.Source & vbCrLf
    '    sErrMsg = sErrMsg & "Number: " & Err.Number & vbCrLf
    '    sErrMsg = sErrMsg & "Description: " & Err.Description
    '    'App.LogEvent(sErrMsg, vbLogEventTypeError)
    '    'Debug.Print(sErrMsg)
    'End Sub



End Class
